#!/bin/sh

root_dir=`pwd`
cd $root_dir

build_dir=$root_dir/../output/Darwin/arm64/Release

rm -rf qeubee_arm64.app
mkdir -p qeubee_arm64.app/Contents/MacOS/ && cp $build_dir/qeubee qeubee_arm64.app/Contents/MacOS/qeubee_arm64
mkdir -p qeubee_arm64.app/Contents/Libraries/ && cp $build_dir/*.dylib qeubee_arm64.app/Contents/Libraries/
mkdir -p qeubee_arm64.app/Contents/Frameworks/ && cp -R $root_dir/../3rdParty/QCefView/out/macos.arm64/QCefViewarm64/lib/QCefViewarm64.framework  qeubee_arm64.app/Contents/Frameworks/
find qeubee_arm64.app/Contents/Frameworks/QCefViewarm64.framework/ -name Headers | xargs rm -rf 
find qeubee_arm64.app/Contents/Frameworks/QCefViewarm64.framework/ -name _CodeSignature | xargs -I {} rm -rf "{}"
cp -r $build_dir/config qeubee_arm64.app/Contents/MacOS/
sed -i '' 's/"\."/"..\/Libraries"/g'  qeubee_arm64.app/Contents/MacOS/config/modules.cfg
/opt/homebrew/opt/qt@5/bin/macdeployqt qeubee_arm64.app -executable=qeubee_arm64.app/Contents/Frameworks/QCefViewarm64.framework/Versions/Current/QCefViewarm64
find qeubee_arm64.app/Contents/ -name "*.prl" -type f -delete

build_dir=$root_dir/../output/Darwin/x86_64/Release
rm -rf qeubee_x86_64.app
mkdir -p qeubee_x86_64.app/Contents/MacOS/ && cp $build_dir/qeubee qeubee_x86_64.app/Contents/MacOS/qeubee_x86_64
mkdir -p qeubee_x86_64.app/Contents/Libraries/ && cp $build_dir/*.dylib qeubee_x86_64.app/Contents/Libraries/
mkdir -p qeubee_x86_64.app/Contents/Frameworks/ && cp -R $root_dir/../3rdParty/QCefView/out/macos.x86_64/QCefViewx86_64/lib/QCefViewx86_64.framework  qeubee_x86_64.app/Contents/Frameworks/
find qeubee_x86_64.app/Contents/Frameworks/QCefViewx86_64.framework/ -name Headers | xargs rm -rf 
find qeubee_x86_64.app/Contents/Frameworks/QCefViewx86_64.framework/ -name _CodeSignature | xargs -I {} rm -rf "{}"
cp -r $build_dir/config qeubee_x86_64.app/Contents/MacOS/
sed -i '' 's/"\."/"..\/Libraries"/g'  qeubee_x86_64.app/Contents/MacOS/config/modules.cfg
arch -x86_64 /usr/local/opt/qt@5/bin/macdeployqt qeubee_x86_64.app -executable=qeubee_x86_64.app/Contents/Frameworks/QCefViewx86_64.framework/Versions/Current/QCefViewx86_64
find qeubee_arm64.app/Contents/ -name "*.prl" -type f -delete





# codesign --deep --force --verbose --sign "Mac Developer: 沈 浩杰 (7J2LY5RWZ3)" ./qeubee_x86_64.app

# rm qeubee_x86_64.dmg

# create-dmg qeubee_x86_64.dmg qeubee_x86_64.app